//
//  Logout.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/20.
//

#import "Logout.h"

@implementation Logout

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
-(void)setupUI
{
    UIView *view = [UIView new];
    [self addSubview:view];
    view.backgroundColor = UIColor.clearColor;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(0);
        make.left.mas_offset(17);
        make.right.mas_offset(-17);
        make.height.mas_equalTo(384);
    }];
    UIImageView *bgIV = [[UIImageView alloc] initWithFrame:self.bounds];
    bgIV.image = [UIImage imageNamed:@"logoutbg"];
    [view addSubview:bgIV];
    [view sendSubviewToBack:bgIV];
    [bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_offset(0);
        make.bottom.mas_offset(-50);
    }];

    UILabel *lab = [UILabel new];
    lab.textColor = HexColor(@"#000000");
    lab.font = [UIFont systemFontOfSize:28 weight:UIFontWeightBold];
    lab.text = @"Logout";
    [view addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(118);
        make.centerX.mas_equalTo(view);
    }];
    UILabel *detail = [UILabel new];
    detail.numberOfLines = 0;
    detail.text = @"Are you sure you want to log out? You may miss some important information after exiting";
    detail.textColor = HexColor(@"#000000");
    detail.textAlignment = NSTextAlignmentCenter;
    detail.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    [view addSubview:detail];
    [detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab.mas_bottom).offset(22);
        make.left.mas_offset(17*2);
        make.right.mas_offset(-17*2);
    }];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[UIImage imageNamed:@"logout"] forState:UIControlStateNormal];
    [btn setTitle:@"Cancel" forState:UIControlStateNormal];
    [btn setTitleColor:HexColor(@"#ffffff") forState:UIControlStateNormal];
    [btn setBackgroundColor:HexColor(@"#2C64FF")];
    btn.layer.cornerRadius = 25;

    btn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
    [view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(16);
        make.right.mas_offset(-16);
        make.height.mas_equalTo(50);
        make.top.equalTo(detail.mas_bottom).mas_offset(20);
    }];
    
    UIButton *close = [UIButton buttonWithType:UIButtonTypeCustom];
    [close setTitle:@"Exit >" forState:UIControlStateNormal];
    [close setTitleColor:HexColor(@"#D7D7D7") forState:UIControlStateNormal];
    close.titleLabel.font = [UIFont systemFontOfSize:16];

    [self addSubview:close];
    [close mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.bottom.mas_offset(-20);
    }];
    [close addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    [btn addTarget:self action:@selector(apply) forControlEvents:UIControlEventTouchUpInside];


}
-(void)close
{
    if (self.closeAction) {
        self.closeAction();
    }}
-(void)apply
{
    if(self.commitAction) {
        self.commitAction();
    }
}

@end
